﻿using Framework;
using UnityEngine;
using View;

public class Starter : MonoSingleton<Starter>
{
    public override void Awake()
	{
		base.Awake();
		Screen.sleepTimeout = SleepTimeout.NeverSleep;
		Application.targetFrameRate = 30;
		
		gameObject.AddComponent<UILayerManager>();
		gameObject.AddComponent<ScheduleManager>();
		AdjustResolution();
	}

	private void AdjustResolution()
	{
		float sourceAspect = Camera.main.aspect;
		float targetAspect = sourceAspect;
		if (targetAspect < Config.MinAspect)
		{
			targetAspect = Config.MinAspect;
		}
		else if (targetAspect > Config.MaxAspect)
		{
			targetAspect = Config.MaxAspect;
		}
		Camera.main.orthographicSize = 0.5f * Config.UnitPerPixel * Config.PreferResolutionWidth / targetAspect;

		UILayerManager.instance.SetPreferResolution(Config.PreferResolutionWidth, Config.MinAspect, Config.MaxAspect);
	}

	// Use this for initialization 
	public void Start ()
	{
		new LoginView().Show();
	}
}
